var com = com || {};
com.em = com.em ||{};

com.em.Wizard = function (privilege, role){
	this.alert;
	// init plugin jgrowl
	this.initAlert();
	// amount tabs
	this.amountTabs = 3;
	// object tabs jquery-ui
	this.tabs = null;
	// com.em.Privilege
	this.privileges = null;
	// com.em.Role
	this.roles = null;
};
com.em.Wizard.prototype = {
	initAlert : function() {
		alert = new com.em.Alert();
	},
	
	/**
	 * 
	 * @param selector
	 */
	configureTabs : function(selector){with (this) {
		tabs = $(selector).tabs({
			select: function(event, ui) {
				switch (ui.index) {
					case 1: return privileges.isEmpty();
						break;
	
					case 2: return ( privileges.isEmpty() && roles.isEmpty() );
						break;
						
					default: return true;
						break;
				}
			}
		});
		$( selector ).parent().css('font-size','0.6em');
	}},
	
	/**
	 * next tab
	 * @param selector
	 */
	clickToNext : function(selector) {with (this){
		$(selector).bind('click', function(event) {
			event.preventDefault();
			length = tabs.tabs('length');
			var next = tabs.tabs('option','selected') + 1;
			if (next < length) {
				tabs.tabs('select', next);
			}
		});
	}},
	
	/**
	 * back to previous tab
	 * @param selector
	 */
	clickToBack : function(selector) {with (this){
		$(selector).bind('click', function(event) {
			event.preventDefault();
			var back = tabs.tabs('option','selected') - 1;
			if (back > -1 ) {
				tabs.tabs('select', back);
			}
		});
	}},
	
	/**
	 * Object com.em.Privilege
	 * @param roles com.em.Privilege
	 */
	setPrivilege : function(privileges) {
		this.privileges = privileges;
	},
	
	/**
	 * Object com.em.Role
	 * @param roles com.em.Role
	 */
	setRole : function(roles) {
		this.roles = roles;
	}
};